// Copyright (C) 2008 Taylor L. Riche <riche@cs.utexas.edu>
//  
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//

package appcomp.entities;

import java.io.PrintStream;

import core.*;
import utility.*;

/**
 * @author riche
 *
 */
public class Connector extends Entity {
	
	final Pair<String, String> inName;
	final Pair<String, String> outName;
	Operator in;
	Operator out;

	/**
	 * @return the in
	 */
	public Operator getIn() {
		return in;
	}

	/**
	 * @return the out
	 */
	public Operator getOut() {
		return out;
	}

	/**
	 * @param i
	 * @param o
	 */
	protected Connector(Pair<String, String> i, Pair<String, String> o) {
		this.inName = i;
		this.outName = o;
	}

	static public Connector create(Pair<String, String> i, Pair<String, String> o) {
		return new Connector(i,o);
	}
	/* (non-Javadoc)
	 * @see appcomp.entities.Entity#generateCode()
	 */
	@Override
	public void generateCode(CodeGenerator cg) {
	}
	
	/* (non-Javadoc)
	 * @see core.Entity#generateFrameworkCode(java.io.PrintStream)
	 */
	@Override
	public void generateFrameworkCode(PrintStream file) {
		file.println("\t\ttempPair = new std::pair<lagniappe::CoreOp *, std::string>(opMap[\"" + this.outName.getLeft() + "\"], \""+ this.outName.getRight() + "\");");
		file.println("\t\topMap[\"" + this.inName.getLeft() + "\"]->setDestination(\"" + this.inName.getRight() + "\", tempPair);");
	}

	public void resolve(CodeGenerator cg) {
		this.in = (Operator)cg.lookupName(this.inName.getLeft());
		this.out = (Operator)cg.lookupName(this.outName.getLeft());
	}

	/**
	 * @return the inName
	 */
	public Pair<String, String> getInName() {
		return inName;
	}

	/**
	 * @return the outName
	 */
	public Pair<String, String> getOutName() {
		return outName;
	}

	/**
	 * @param in the in to set
	 */
	public void setIn(Operator in) {
		this.in = in;
	}

	/**
	 * @param out the out to set
	 */
	public void setOut(Operator out) {
		this.out = out;
	}
	

}
